//
//  SADateUtil.m
//  SABlueToothAPP
//
//  Created by brave on 11/07/25.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SADateUtil.h"


@implementation SADateUtil

//NSDateを「yyyy/MM/dd tt:mm:ss」のフォーマットStringにして返す
+(NSString*)NSDateToFormatString:(NSDate*)date{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY/MM/DD HH:mm"];
    NSString *str = [formatter stringFromDate:date];
    
    [ formatter release ];
    
    return str;
}

// NSDateを画Stringで返す
+(NSString*)TimeToFormatString:(NSDate*)date{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm"];
    NSString *str = [formatter stringFromDate:date];
    
    [ formatter release ];
    
    return str;
}

// hourとminを配列で取得
+(NSArray*)hourMinToFormatString:(NSDate*)date{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH"];
    NSString *hour = [formatter stringFromDate:date];
    [formatter setDateFormat:@"mm"];
    NSString *min = [formatter stringFromDate:date];
    
    [ formatter release ];
    
    return [[[ NSArray alloc ]initWithObjects:hour,min, nil] autorelease];
}



/* Twitter NSDate */

// Twitterの「CreateAt」をNSDataに変換
+(NSDate*)dateFromCreatedAtDateString:(NSString*)strDate {
    // Setting DateFormatter
    static NSDateFormatter* format = nil;
    if (format == nil) {
        format = [[NSDateFormatter alloc] init];
        [format setDateStyle:NSDateFormatterLongStyle];
        [format setTimeStyle:NSDateFormatterNoStyle];
        [format setDateFormat:@"EEE MMM dd HH:mm:ss Z yyyy"];
    }
    return [format dateFromString:strDate];
}


@end
